package com.mryx.demo.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.mryx.demo.mapper.UserMapper;
import com.mryx.demo.pojo.User;
import com.mryx.demo.service.UserService;
import com.mryx.demo.util.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService{
    @Resource(name="userMapper")
    UserMapper userMapper;

    @Resource
    PageHelper pageHelper;
    @Override
    public Integer updAddress(User user) {
        return userMapper.updAddress(user);
    }

    @Override
    public Integer getIntegral(Integer uid) { return userMapper.getIntegral(uid); }

    @Override
    public Integer updPayPwd(User user) { return userMapper.updPayPwd(user);}

    @Override
    public Integer updPhone(User user) { return userMapper.updPhone(user);}

    @Override
    public Double getBalance(Integer uid) { return userMapper.getBalance(uid);}

    @Override
    public Integer updBalance(User user) { return  userMapper.updBalance(user);}

    @Override
    public Integer updState(User user) {
        if(user.getState() == 0){
            return userMapper.Prohibition(user);
        }else{
            return userMapper.Unsealing(user);
        }
    }

    @Override
    public User getInfo(Integer uid) { return userMapper.getInfo(uid); }

    @Override
    public PageBean<User> getAllUser(Integer currentPage,Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<User> users = userMapper.getAllUser();
        Integer count = userMapper.userCount();
        PageBean<User> pages = new PageBean<>(currentPage,pageSize,count);
        pages.setItems(users);
        return pages;
    }

    @Override
    public User getUserByPhone(String pehoneNum) { return userMapper.getUserByPhone(pehoneNum); }

    @Override
    public Integer register(String pehoneNum) { return userMapper.register(pehoneNum); }

}
